package config

import (
	"context"
	"go-caipu/pkg/services/dto"
)

type GetSysConfigPageCommand struct {
	dto.Pagination `search:"-"`
	ConfigName     string `form:"configName"  search:"type:exact;column:config_name;table:sys_config" comment:"参数名称"`
	ConfigKey      string `form:"configKey"  search:"type:exact;column:config_key;table:sys_config" comment:"参数键值"`
	ConfigType     string `form:"configType"  search:"type:exact;column:config_type;table:sys_config" comment:"系统内置"`
	IsFrontend     string `form:"isFrontend" search:"type:exact;column:is_frontend;table:sys_config" comment:"前台显示"`
}

type SysConfig struct {
	ConfigId    int64       `json:"id" gorm:"type:bigint;comment:config_id"`
	ConfigName  string      `json:"name" gorm:"type:varchar(255);comment:参数名称"`
	ConfigKey   string      `json:"code" gorm:"type:varchar(255);comment:参数键值"`
	ConfigValue interface{} `json:"value"`
	Sort        int         `json:"sort" gorm:"type:int;comment:排序"`
	ConfigType  string      `json:"configType" gorm:"type:varchar(64);comment:系统内置"`
	IsFrontend  int         `json:"isFrontend" gorm:"type:int;comment:前台显示"`
	Remark      string      `json:"description" gorm:"type:varchar(255);comment:Remark"`
	dto.ControlBy
	dto.ModelTime
}

func (m *GetSysConfigPageCommand) GetNeedSearch() interface{} {
	return *m
}

type GetSysConfigCommand struct {
	Id int64 `uri:"id"`
}

type RemoveSysConfigCommand struct {
	Ids []int64 `json:"ids"`
}
type GetConfigsByKeyCommand struct {
	Code     []string `json:"code" search:"type:in;column:config_key;table:sys_config"`
	Category string   `json:"category,omitempty" search:"type:startswith;column:config_key;table:sys_config"`
}

func (cmd *GetConfigsByKeyCommand) GetNeedSearch() interface{} {
	return *cmd
}

type SysCofig struct {
}

// Service 业务接口
type Service interface {
	GetSysConfigPage(ctx context.Context, cmd GetSysConfigPageCommand) (data []SysConfig, num int64, err error)
	Get(ctx context.Context, cmd GetSysConfigCommand) (SysConfig, error)
	Insert(ctx context.Context, cmd SysConfig) error
	Update(ctx context.Context, cmd SysConfig) error
	Remove(ctx context.Context, cmd RemoveSysConfigCommand) error
	GetConfigsByKey(ctx context.Context, cmd GetConfigsByKeyCommand) (data []SysConfig, err error)
}
